package com.hulk.dryad.manage.framework.datasource.config;


import com.baomidou.dynamic.datasource.processor.DsProcessor;
import com.baomidou.dynamic.datasource.processor.DsSpelExpressionProcessor;
import com.hulk.dryad.manage.framework.datasource.dynamic.DsHeaderProcessor;
import com.hulk.dryad.manage.framework.datasource.dynamic.DsSessionProcessor;
import com.hulk.dryad.manage.framework.datasource.dynamic.DsThreadLocalProcessor;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author hulk
 * @version 1.0
 * @date 2020/10/21 3:58 下午
 */
@Configuration
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
@RequiredArgsConstructor
public class DynamicDsAutoConfiguration {


	@Bean
	public DsProcessor dsProcessor() {

		DsThreadLocalProcessor dsThreadLocalProcessor = new DsThreadLocalProcessor();
		DsSessionProcessor sessionProcessor = new DsSessionProcessor();
		DsSpelExpressionProcessor expressionProcessor = new DsSpelExpressionProcessor();
		dsThreadLocalProcessor.setNextProcessor(sessionProcessor);
		sessionProcessor.setNextProcessor(expressionProcessor);

		//DsHeaderProcessor headerProcessor = new DsHeaderProcessor();
		//headerProcessor.setNextProcessor(sessionProcessor);
		return dsThreadLocalProcessor;
	}


}
